package pictionary2;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */




import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 *
 * @author Viper
 */
public class VentanaNombre {
    private JLabel miNombre;
    private JTextField auxT;
    private JFrame auxF;
    private boolean ban;

    public VentanaNombre() {
        Escuchador escu= new Escuchador();
       // setDefaultCloseOperation(EXIT_ON_CLOSE);
        auxF= new JFrame("Nombre");
        JPanel auxP= new JPanel();
        miNombre = new JLabel();
        miNombre.setText("Dame tu nombre");
        auxT= new JTextField();
        auxT.setText("");
        ban=false;
        JButton auxB= new JButton();
        auxT.setPreferredSize(new Dimension(100,20));
        auxB.setText("Aceptar");
        auxB.setActionCommand("Aceptar");
        auxT.setActionCommand("Aceptar");
        auxB.addActionListener(escu);
        auxT.addActionListener(escu);
        auxP.setLayout(new FlowLayout());
        auxP.add(auxT);
        auxP.add(auxB);
        //auxP.setPreferredSize(new Dimension (40,500));
        auxF.add(auxP);
        auxF.pack();
        auxF.setFocusable(true);
        auxF.requestFocus();
        auxF.setState(Frame.NORMAL);
        auxF.setAlwaysOnTop(true);
        auxF.setVisible(true);
    }

    public String getNombre(){
        return auxT.getText();
    }

    public boolean getBan(){
        return ban;
    }
    class Escuchador implements ActionListener{

        public void actionPerformed(ActionEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
       // JOptionPane.showMessageDialog(null, "Adios");
        //JButton btn = (JButton)e.getSource();
        String comando = e.getActionCommand();
        if(comando.equals("Aceptar")){
            if(!auxT.getText().equals("")){
                miNombre.setText(auxT.getText());
                auxF.setVisible(false);
                ban=true;
            }
         }
        }
     }
}
